package com.yuyou.weixin.controller;

import com.yuyou.weixin.service.ISrsActivityService;
import com.yuyou.weixin.service.ISrsActivityUserRelationService;
import com.yuyou.weixin.util.Webs;
import com.yuyou.weixin.vo.resp.UserAssistStatisExcel;
import com.yuyou.weixin.vo.resp.UserInfoExcel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by yujin.liu on 2018/11/12.
 */
@RestController
@RequestMapping("/api/dataHandle")
public class DataHandleController {

    @Autowired
    private ISrsActivityUserRelationService srsActivityUserRelationService;

    @Autowired
    private ISrsActivityService srsActivityService;

    @ApiOperation(value = "用户助力统计")
    @RequestMapping(value="/userAssistStatis" ,method= {RequestMethod.POST, RequestMethod.GET})
    public String userAssistStatis(HttpServletRequest request, HttpServletResponse response, String projectCode, String key) throws Exception{
        if(!key.equals("!@$yuyou123321")){
            return "hei hei !";
        }
        String fileName = "用户助力统计";
        Webs.writeExcel(request, response, fileName, srsActivityUserRelationService.findUserAssistStatis(projectCode), UserAssistStatisExcel.class);
        return "ok";
    }

    @ApiOperation(value = "用户信息")
    @RequestMapping(value="/userInfo" ,method= {RequestMethod.POST, RequestMethod.GET})
    public String userInfo(HttpServletRequest request, HttpServletResponse response, String projectCode, String key) throws Exception{
        if(!key.equals("!@$yuyou123321")){
            return "hei hei !";
        }
        String fileName = "用户信息";
        Webs.writeExcel(request, response, fileName, srsActivityService.findUserInfo(projectCode), UserInfoExcel.class);
        return "ok";
    }
}
